package com.open.capacity.course.controller;

import com.open.capacity.common.model.Course;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.course.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/course")
@Api(tags = "课程管理")
public class CourseController {

    @Autowired
    private CourseService courseService;

    // 根据id查询课程
    @PostMapping("/selectCourseById/{id}")
    @ApiOperation(value = "根据id查询课程")
    public Result selectCourseById(@PathVariable("id") int id){
        return courseService.selectCourseById(id);
    }

    // 模糊查询课程
    @PostMapping("/getSelectCourses")
    @ApiOperation(value = "模糊查询课程")
    public PageResult<Course> getSelectCourses(@RequestParam Map<String, Object> params){
        return courseService.getSelectCourses(params);
    }

    // 添加课程
    @PostMapping("/addCourse")
    @ApiOperation(value = "添加课程")
    public Result addCourse(@RequestBody Course course){
        return courseService.addCourse(course);
    }

    // 修改课程
    @PostMapping("/updateCourse")
    @ApiOperation(value = "修改课程")
    public Result updateCourse(@RequestBody Course course){
        return courseService.updateCourse(course);
    }

    // 删除课程
    @DeleteMapping("/delCourse/{id}")
    @ApiOperation(value = "删除课程")
    public Result delCourse(@PathVariable("id") int id){
        return courseService.delCourse(id);
    }

}
